#############
#Figure 1: Individuals' Actual and Perceived Risk Exposure
#############

setwd("~/Desktop")
data<-read.csv("risk.csv")
head(data)
data$actual_risk<- ifelse(data$actual_riskexposure>3.5 & data$actual_riskexposure<5.1,1,
                      ifelse(data$actual_riskexposure>5.1 & data$actual_riskexposure<7.1,2,
                             ifelse(data$actual_riskexposure>7.1,3,0)))
mytable<-table(data$actual_risk,data$fin_insecure)
data$perrisk<- ifelse(data$fin_insecure=="Very insecure",7,
                      ifelse(data$fin_insecure=="Insecure",6,
                             ifelse(data$fin_insecure=="Somewhat insecure",5,
                               ifelse(data$fin_insecure=="Neither secure nor insecure",4,          
                                    ifelse(data$fin_insecure=="Somewhat secure",3,
                                           ifelse(data$fin_insecure=="Secure",2,
                                             ifelse(data$fin_insecure=="Very secure",1,0)))))))
mytable<-table(data$actual_risk,data$perrisk)
mytable
freq<-prop.table(mytable,1)
barplot(freq , border="black",  col="black",density=c(0,10,60), font.axis=1, beside=T, xlab="Perceived Risk Exposure", ylab="Sample Frequencies", cex.names=.6,names.arg=c("Very Secure", "Secure", "Somewhat Secure", "Neither Secure Nor Insecure", "Somewhat Insecure", "Insecure", "Very Insecure"), font.lab=1)
legend("topright", inset=-.02, cex=.75, box.col="white", c("Low Risk Exposure","Moderate Risk Exposure","High Risk Exposure"), density=c(0,10,60))

#############
#Figure 2: The Marginal Effect of a One-Unit Increase in Perceived Risk Exposure on an Individual's Support for Federal Welfare Spending
#############

#Figure Created in STATA
#See Attached Do File

#############
#Figure 3a: Ego-Centric Risk Exposure
#############
par(mfrow=c(1,2))

height<- cbind( .48, .22, 0, .07,.33)
par(cex=1, cex.sub=.5, cex.lab=1.1, family="sans")
barplot(height, 
	width=.5,
	col="grey94",
	xlim=c(0,5),
	ylim=c(0,.8),
	ylab="Pr(Support Increased Welfare Spending)",
	axes=FALSE)
x.space<-c("","","","","")
axis(side=2)

mtext("Low", side=1, at=.33,.01, cex=.7)
mtext("High", side=1, at=.98, .01, cex=.7)
mtext("Low", side=1, at=2.12,.01, cex=.7)
mtext("High", side=1, at=2.79,.01, cex=.7)

mtext("Perceived Risk Exposure", side=1, at=2.5,1, cex=.8)
mtext("Perceived Risk Exposure", side=1, at=.68,1, cex=.8)

mtext("Risk Acceptant", side=1, at=.65,2.5, cex=.98, family="sans")
mtext("Risk Averse", side=1, at=2.55,2.5, cex=.98, family="sans")

mtext("Ego-centric Risk Exposure: 
Perceived Financial Insecurity", side=1, at=1.5,-27, cex=.98, family="sans")

abline(0, 0)

points(.35,.48, pch=19)
points(.35,.36, pch="------")
points(.35,.62, pch="-")
lines(c(.35,.36),c(.36, .62))

points(.96,.22,pch=19)
points(.96,.10, pch="-")
points(.96,.38, pch="-")
lines(c(.96,.96),c(.10,.38))

points(2.12,.07, pch=19)
points(2.12,.02, pch="-")
points(2.12, .18, pch="-")
lines(c(2.12,2.12),c(.18,.02))

points(2.75,.33, pch=19)
points(2.75, .19, pch="-")
points(2.75,.49, pch="-")
lines(c(2.75,2.75),c(.49,.19))

##############
#Figure3b: Socio-tropic Risk Exposure
##############

height<- cbind( .43, .18, 0, .18,.25)
par(cex=1, cex.sub=.5, cex.lab=1.1, family="sans")
barplot(height, 
	width=.5,
	col="grey94",
	xlim=c(0,5),
	ylim=c(0,.8),
	ylab="Pr(Support Increased Welfare Spending)",
	axes=FALSE)
x.space<-c("","","","","")
axis(side=2)

mtext("Low", side=1, at=.33,.01, cex=.7)
mtext("High", side=1, at=.98, .01, cex=.7)
mtext("Low", side=1, at=2.12,.01, cex=.7)
mtext("High", side=1, at=2.79,.01, cex=.7)

mtext("Perceived Risk Exposure", side=1, at=2.5,1, cex=.8)
mtext("Perceived Risk Exposure", side=1, at=.68,1, cex=.8)

mtext("Risk Acceptant", side=1, at=.65,2.5, cex=.98, family="sans")
mtext("Risk Averse", side=1, at=2.55,2.5, cex=.98, family="sans")
abline(0, 0)

mtext("Socio-tropic Risk Exposure: 
Perceived Macroeconomic Health", side=1, at=1.5,-27, cex=.98, family="sans")

points(.35,.43, pch=19)
points(.35,.33, pch="------")
points(.35,.53, pch="-")
lines(c(.35,.35),c(.33, .53))

points(.96,.18,pch=19)
points(.96,.09, pch="-")
points(.96,.30, pch="-")
lines(c(.96,.96),c(.09,.30))

points(2.12,.18, pch=19)
points(2.12,.10, pch="-")
points(2.12, .28, pch="-")
lines(c(2.12,2.12),c(.10,.28))

points(2.75,.25, pch=19)
points(2.75, .12, pch="-")
points(2.75,.43, pch="-")
lines(c(2.75,2.75),c(.12,.43))


